Declare @noOfMin as smallint
Select @noOfMin = CASE
		WHEN CAST(GetDate() AS Time(0)) Between '08:00:00' AND '10:00:00' THEN 120
		WHEN CAST(GetDate() AS Time(0)) Between '13:00:01' AND '14:00:00' THEN 120
		ELSE 60
		END

Declare @CurrentTime as smallint
Select @CurrentTime = CASE
		WHEN CAST(GetDate() AS Time(0)) Between '08:00:00' AND '10:00:00' THEN 100
		WHEN CAST(GetDate() AS Time(0)) Between '13:00:01' AND '14:00:00' THEN 200
		ELSE 300
		END


Declare @StartTime DateTime
Declare @EndTime DateTime

SET @StartTime = DateAdd(minute, (@noOfMin * -1), GetDate())
SET @EndTime = GetDate()

Select @noOfMin NoOfMin, @CurrentTime CurrentTime, @StartTime StartTime, @EndTime EndTime

IF @CurrentTime = 100
BEGIN
	SELECT DISTINCT CEID FROM tblLoginHistory WHERE UsrTypeID = 200 
	And EndTime Between @StartTime And @EndTime
END
ELSE
BEGIN
	SELECT DISTINCT AgentID FROM tblCXCRMAgentLeads WHERE ModifiedDate Between @StartTime And @EndTime
	UNION
	SELECT DISTINCT AgentID FROM tblNonGGCarMoreDetails WHERE ModifiedDate Between @StartTime And @EndTime
	UNION
	SELECT DISTINCT AgentID FROM tblCXBrokerPremium WHERE ModifiedDate Between @StartTime And @EndTime
	UNION
	SELECT DISTINCT AgentID FROM tblPayments WHERE ModifiedDate Between @StartTime And @EndTime
END